import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.geom.AffineTransform;


public class Laser extends Entity{
	
	private double lx=0;
	private double ly=0;
	private double speed=0;
	private Color c;
	private double a=0,b=1;
	private double theta=0;
	AffineTransform affineTransform = new AffineTransform();
	AffineTransform affineTransform2;
	
	public Laser(){
		lx=0;
		ly=0;
		speed=0;
	}

	@Override
	public void draw(Graphics g) {
		// TODO Auto-generated method stub
		c = g.getColor();
		g.setColor(Color.RED);
		Graphics2D g2 = (Graphics2D) g;
		affineTransform2 = g2.getTransform();
		affineTransform.rotate(theta, lx, ly);
		g2.setTransform(affineTransform);
		g2.fillRect((int)lx, (int)ly, 3, 50);
		affineTransform.rotate(-theta, lx, ly);
		g2.setTransform(affineTransform);
		g2.setTransform(affineTransform2);
		g.setColor(c);
	}

	@Override
	public void move() {
		// TODO Auto-generated method stub
		lx-=a*speed;
		ly-=b*speed;
	}

	@Override
	public void move(double dx, double dy) {

	}

	@Override
	public void setX(double x) {
		// TODO Auto-generated method stub
		lx=x;
		
	}

	@Override
	public void setY(double y) {
		// TODO Auto-generated method stub
		ly=y;
	}
	
	public void setVect(double dx, double dy){
		double a1 = a;
		double b1 = b;
		a=(lx-dx)/Math.pow(Math.pow((dx-lx),2)+Math.pow((dy-ly),2),0.5);
		b=(ly-dy)/Math.pow(Math.pow((dx-lx),2)+Math.pow((dy-ly),2),0.5);
		theta += (Math.atan2(b,a)-Math.atan2(b1,a1));
	}
	
	public void setSpeed(double speedy) {
		// TODO Auto-generated method stub
		speed=speedy;
	}

	@Override
	public double getX() {
		return lx;
		// TODO Auto-generated method stub
		
	}
	
	public Rectangle getBounds(){
		return new Rectangle((int) lx, (int) ly, 3, 1);
	}

	@Override
	public double getY() {
		return ly;
		// TODO Auto-generated method stub
		
	}

	@Override
	public int getCadence() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void setLife() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public int getLife() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public boolean getFin() {
		// TODO Auto-generated method stub
		return false;
	}
	
}
